/*     */ package com.zimbra.cs.account;
/*     */ 
/*     */ import com.google.common.base.Splitter;
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId;
/*     */ import java.util.Arrays;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SearchDirectoryOptions
/*     */ {
/*     */   public static final int ALL_RESULTS = 0;
/*  33 */   public static final String[] ALL_ATTRS = null;
/*  34 */   public static final SortOpt DEFAULT_SORT_OPT = SortOpt.NO_SORT;
/*  35 */   public static final String DEFAULT_SORT_ATTR = null;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static final String SORT_BY_TARGET_NAME = "targetName";
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public SearchDirectoryOptions() {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static enum MakeObjectOpt
/*     */   {
/*  56 */     ALL_DEFAULTS, 
/*  57 */     NO_DEFAULTS, 
/*  58 */     NO_SECONDARY_DEFAULTS;
/*     */     
/*     */     private MakeObjectOpt() {} }
/*     */   
/*  62 */   public static enum SortOpt { NO_SORT, 
/*  63 */     SORT_ASCENDING, 
/*  64 */     SORT_DESCENDING;
/*     */     
/*     */     private SortOpt() {} }
/*     */   
/*  68 */   public static enum ObjectType { accounts(1), 
/*  69 */     aliases(2), 
/*  70 */     distributionlists(4), 
/*  71 */     dynamicgroups(256), 
/*  72 */     resources(8), 
/*  73 */     domains(16), 
/*  74 */     coses(32), 
/*  75 */     servers(64), 
/*  76 */     ucservices(128);
/*     */     
/*     */     private int flag;
/*     */     
/*  80 */     private ObjectType(int flag) { this.flag = flag; }
/*     */     
/*     */     public int getFlag()
/*     */     {
/*  84 */       return this.flag;
/*     */     }
/*     */     
/*     */     public static int getAllTypesFlags() {
/*  88 */       int flags = 0;
/*  89 */       for (ObjectType type : values()) {
/*  90 */         flags |= type.getFlag();
/*     */       }
/*  92 */       return flags;
/*     */     }
/*     */     
/*     */     public static int getFlags(Set<ObjectType> types) {
/*  96 */       int flags = 0;
/*  97 */       for (ObjectType type : types) {
/*  98 */         flags |= type.getFlag();
/*     */       }
/* 100 */       return flags;
/*     */     }
/*     */     
/*     */     public static Set<ObjectType> fromCSVString(String str) throws ServiceException
/*     */     {
/* 105 */       Set<ObjectType> types = Sets.newHashSet();
/* 106 */       for (String type : Splitter.on(',').trimResults().split(str)) {
/* 107 */         types.add(fromString(type));
/*     */       }
/* 109 */       return types;
/*     */     }
/*     */     
/*     */     public static String toCSVString(Set<ObjectType> types) {
/* 113 */       StringBuilder sb = new StringBuilder();
/*     */       
/* 115 */       boolean first = true;
/* 116 */       for (ObjectType type : types) {
/* 117 */         if (!first) {
/* 118 */           sb.append(",");
/*     */         } else {
/* 120 */           first = false;
/*     */         }
/* 122 */         sb.append(type.name());
/*     */       }
/* 124 */       return sb.toString();
/*     */     }
/*     */     
/*     */     public static ObjectType fromString(String str) throws ServiceException {
/*     */       try {
/* 129 */         return valueOf(str);
/*     */       } catch (IllegalArgumentException e) {
/* 131 */         throw ServiceException.INVALID_REQUEST("unknown type: " + str, e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/* 136 */   private boolean onMaster = false;
/* 137 */   private final boolean useConnPool = true;
/* 138 */   private int maxResults = 0;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 146 */   private Domain domain = null;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private ZLdapFilter filter;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private ZLdapFilterFactory.FilterId filterId;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private String filterStr;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private Set<ObjectType> types;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 177 */   private String[] returnAttrs = ALL_ATTRS;
/* 178 */   private MakeObjectOpt makeObjOpt = MakeObjectOpt.ALL_DEFAULTS;
/* 179 */   private SortOpt sortOpt = DEFAULT_SORT_OPT;
/* 180 */   private String sortAttr = DEFAULT_SORT_ATTR;
/*     */   private boolean convertIDNToAscii;
/* 182 */   private boolean isUseControl = true;
/* 183 */   private boolean isManageDSAit = false;
/*     */   
/*     */ 
/*     */ 
/*     */   public SearchDirectoryOptions(Domain domain)
/*     */   {
/* 189 */     setDomain(domain);
/*     */   }
/*     */   
/*     */   public SearchDirectoryOptions(String[] returnAttrs) {
/* 193 */     setReturnAttrs(returnAttrs);
/*     */   }
/*     */   
/*     */   public SearchDirectoryOptions(Domain domain, String[] returnAttrs) {
/* 197 */     setDomain(domain);
/* 198 */     setReturnAttrs(returnAttrs);
/*     */   }
/*     */   
/*     */   public boolean equals(Object o)
/*     */   {
/* 203 */     if (!(o instanceof SearchDirectoryOptions)) {
/* 204 */       return false;
/*     */     }
/* 206 */     if (o == this) {
/* 207 */       return true;
/*     */     }
/*     */     
/* 210 */     SearchDirectoryOptions other = (SearchDirectoryOptions)o;
/*     */     
/* 212 */     if (this.onMaster != other.getOnMaster()) {
/* 213 */       return false;
/*     */     }
/*     */     
/* 216 */     if (true != other.getUseConnPool()) {
/* 217 */       return false;
/*     */     }
/*     */     
/* 220 */     if (this.maxResults != other.getMaxResults()) {
/* 221 */       return false;
/*     */     }
/*     */     
/* 224 */     if (this.domain != null) {
/* 225 */       Domain otherDomain = other.getDomain();
/* 226 */       if (otherDomain == null) {
/* 227 */         return false;
/*     */       }
/* 229 */       if (!this.domain.getId().equals(otherDomain.getId())) {
/* 230 */         return false;
/*     */       }
/*     */     }
/* 233 */     else if (other.getDomain() != null) {
/* 234 */       return false;
/*     */     }
/*     */     
/*     */ 
/* 238 */     if (this.filter != null) {
/* 239 */       ZLdapFilter otherFilter = other.getFilter();
/* 240 */       if (otherFilter == null) {
/* 241 */         return false;
/*     */       }
/* 243 */       if (!this.filter.toFilterString().equals(otherFilter.toFilterString())) {
/* 244 */         return false;
/*     */       }
/*     */       
/*     */     }
/* 248 */     else if (other.getFilter() != null) {
/* 249 */       return false;
/*     */     }
/*     */     
/*     */ 
/* 253 */     if (this.filterId != other.getFilterId()) {
/* 254 */       return false;
/*     */     }
/*     */     
/* 257 */     if (this.filterStr != null) {
/* 258 */       String otherFilterStr = other.getFilterString();
/* 259 */       if (otherFilterStr == null) {
/* 260 */         return false;
/*     */       }
/* 262 */       if (!this.filterStr.equals(otherFilterStr)) {
/* 263 */         return false;
/*     */       }
/*     */       
/*     */     }
/* 267 */     else if (other.getFilterString() != null) {
/* 268 */       return false;
/*     */     }
/*     */     
/*     */ 
/* 272 */     if (getTypesAsFlags() != other.getTypesAsFlags()) {
/* 273 */       return false;
/*     */     }
/*     */     
/* 276 */     if (this.returnAttrs != null) {
/* 277 */       String[] otherReturnAttrs = other.getReturnAttrs();
/* 278 */       if (otherReturnAttrs == null) {
/* 279 */         return false;
/*     */       }
/* 281 */       Set<String> attrsSet = Sets.newHashSet(Arrays.asList(this.returnAttrs));
/* 282 */       Set<String> otherAttrsSet = Sets.newHashSet(Arrays.asList(otherReturnAttrs));
/* 283 */       if (!attrsSet.equals(otherAttrsSet)) {
/* 284 */         return false;
/*     */       }
/*     */       
/*     */     }
/* 288 */     else if (other.getReturnAttrs() != null) {
/* 289 */       return false;
/*     */     }
/*     */     
/*     */ 
/* 293 */     if (this.makeObjOpt != other.getMakeObjectOpt()) {
/* 294 */       return false;
/*     */     }
/*     */     
/* 297 */     if (this.sortOpt != other.getSortOpt()) {
/* 298 */       return false;
/*     */     }
/*     */     
/* 301 */     if (this.sortAttr != null) {
/* 302 */       String otherSortAttr = other.getSortAttr();
/* 303 */       if (otherSortAttr == null) {
/* 304 */         return false;
/*     */       }
/* 306 */       if (!this.sortAttr.equals(otherSortAttr)) {
/* 307 */         return false;
/*     */       }
/*     */       
/*     */     }
/* 311 */     else if (other.getSortAttr() != null) {
/* 312 */       return false;
/*     */     }
/*     */     
/*     */ 
/* 316 */     if (this.convertIDNToAscii != other.getConvertIDNToAscii()) {
/* 317 */       return false;
/*     */     }
/*     */     
/* 320 */     return true;
/*     */   }
/*     */   
/*     */   public void setOnMaster(boolean onMaster) {
/* 324 */     this.onMaster = onMaster;
/*     */   }
/*     */   
/*     */   public boolean getOnMaster() {
/* 328 */     return this.onMaster;
/*     */   }
/*     */   
/*     */   public boolean getUseConnPool() {
/* 332 */     return true;
/*     */   }
/*     */   
/*     */   public void setMaxResults(int maxResults) {
/* 336 */     this.maxResults = maxResults;
/*     */   }
/*     */   
/*     */   public int getMaxResults() {
/* 340 */     return this.maxResults;
/*     */   }
/*     */   
/*     */   public void setDomain(Domain domain) {
/* 344 */     this.domain = domain;
/*     */   }
/*     */   
/*     */   public Domain getDomain() {
/* 348 */     return this.domain;
/*     */   }
/*     */   
/*     */   public void setFilter(ZLdapFilter filter) {
/* 352 */     this.filter = filter;
/*     */   }
/*     */   
/*     */   public ZLdapFilter getFilter() {
/* 356 */     return this.filter;
/*     */   }
/*     */   
/*     */   public void setFilterString(ZLdapFilterFactory.FilterId filterId, String filterStr) {
/* 360 */     this.filterId = filterId;
/* 361 */     this.filterStr = filterStr;
/*     */   }
/*     */   
/*     */   public ZLdapFilterFactory.FilterId getFilterId() {
/* 365 */     return this.filterId;
/*     */   }
/*     */   
/*     */   public String getFilterString() {
/* 369 */     return this.filterStr;
/*     */   }
/*     */   
/*     */   public void setReturnAttrs(String[] returnAttrs) {
/* 373 */     this.returnAttrs = returnAttrs;
/*     */   }
/*     */   
/*     */   public void setTypes(String typesStr) throws ServiceException
/*     */   {
/* 378 */     this.types = ObjectType.fromCSVString(typesStr);
/*     */   }
/*     */   
/*     */   public void setTypes(ObjectType... objTypes) throws ServiceException {
/* 382 */     setTypesInternal(objTypes);
/*     */   }
/*     */   
/*     */   protected void setTypesInternal(ObjectType... objTypes) {
/* 386 */     this.types = Sets.newHashSet();
/* 387 */     for (ObjectType type : objTypes) {
/* 388 */       this.types.add(type);
/*     */     }
/*     */   }
/*     */   
/*     */   public void addType(ObjectType objType) {
/* 393 */     if (this.types == null) {
/* 394 */       this.types = Sets.newHashSet();
/*     */     }
/* 396 */     this.types.add(objType);
/*     */   }
/*     */   
/*     */   public Set<ObjectType> getTypes() {
/* 400 */     return this.types;
/*     */   }
/*     */   
/*     */   public int getTypesAsFlags() {
/* 404 */     return getTypesAsFlags(this.types);
/*     */   }
/*     */   
/*     */   public static int getTypesAsFlags(Set<ObjectType> types) {
/* 408 */     if (types == null) {
/* 409 */       return 0;
/*     */     }
/* 411 */     return ObjectType.getFlags(types);
/*     */   }
/*     */   
/*     */   public String[] getReturnAttrs()
/*     */   {
/* 416 */     return this.returnAttrs;
/*     */   }
/*     */   
/*     */   public void setMakeObjectOpt(MakeObjectOpt makeObjOpt) {
/* 420 */     this.makeObjOpt = makeObjOpt;
/*     */   }
/*     */   
/*     */   public MakeObjectOpt getMakeObjectOpt() {
/* 424 */     return this.makeObjOpt;
/*     */   }
/*     */   
/*     */   public void setSortOpt(SortOpt sortOpt) {
/* 428 */     if (sortOpt == null) {
/* 429 */       sortOpt = DEFAULT_SORT_OPT;
/*     */     }
/* 431 */     this.sortOpt = sortOpt;
/*     */   }
/*     */   
/*     */   public SortOpt getSortOpt() {
/* 435 */     return this.sortOpt;
/*     */   }
/*     */   
/*     */   public void setSortAttr(String sortAttr) {
/* 439 */     this.sortAttr = sortAttr;
/*     */   }
/*     */   
/*     */   public String getSortAttr() {
/* 443 */     return this.sortAttr;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void setConvertIDNToAscii(boolean convertIDNToAscii)
/*     */   {
/* 454 */     this.convertIDNToAscii = convertIDNToAscii;
/*     */   }
/*     */   
/*     */   public boolean getConvertIDNToAscii() {
/* 458 */     return this.convertIDNToAscii;
/*     */   }
/*     */   
/*     */   public boolean isUseControl() {
/* 462 */     return this.isUseControl;
/*     */   }
/*     */   
/*     */   public void setUseControl(boolean isUseControl) {
/* 466 */     this.isUseControl = isUseControl;
/*     */   }
/*     */   
/*     */   public boolean isManageDSAit() {
/* 470 */     return this.isManageDSAit;
/*     */   }
/*     */   
/*     */   public void setManageDSAit(boolean isManageDSAit) {
/* 474 */     this.isManageDSAit = isManageDSAit;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/SearchDirectoryOptions.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */